package cn.iocoder.lw.module.core.service.house;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.lw.framework.common.pojo.PageResult;
import cn.iocoder.lw.framework.common.util.object.BeanUtils;
import cn.iocoder.lw.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.lw.module.core.controller.admin.house.vo.*;
import cn.iocoder.lw.module.core.convert.house.CoreHouseConvert;
import cn.iocoder.lw.module.core.dal.dataobject.house.CoreHouseDO;
import cn.iocoder.lw.module.core.dal.dataobject.project.CoreProjectDO;
import cn.iocoder.lw.module.core.dal.mysql.house.CoreHouseMapper;
import cn.iocoder.lw.module.core.service.project.CoreProjectService;
import cn.iocoder.lw.module.system.api.dept.DeptApi;
import cn.iocoder.lw.module.system.api.dept.dto.DeptRespDTO;
import cn.iocoder.lw.module.system.api.user.AdminUserApi;
import cn.iocoder.lw.module.system.api.user.dto.AdminUserRespDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validator;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import static cn.iocoder.lw.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.lw.module.core.enums.ErrorCodeConstants.*;

/**
 * 核心房源 Service 实现类
 *
 * @author Lw源码
 */
@Service
@Slf4j
public class CoreHouseServiceImpl implements CoreHouseService {

    @Resource
    private CoreHouseMapper houseMapper;

    @Resource
    private CoreProjectService projectService;

    @Resource
    private AdminUserApi adminUserApi;
    @Resource
    private DeptApi deptApi;
    @Resource
    private Validator validator;

    @Override
    public Long createHouse(CoreHouseSaveReqVO createReqVO) {
        // 校验项目存在
        projectService.validateProjectExists(createReqVO.getProjectId());

        // 插入
        CoreHouseDO house = CoreHouseConvert.INSTANCE.convert(createReqVO);

        // 自动生成完整房号
        if (house.getFullRoomNumber() == null || house.getFullRoomNumber().isEmpty()) {
            house.setFullRoomNumber(generateFullRoomNumber(house.getBuilding(), house.getFloor(), house.getRoomNumber()));
        }

        houseMapper.insert(house);
        // 返回
        return house.getId();
    }

    @Override
    public void updateHouse(CoreHouseSaveReqVO updateReqVO) {
        // 校验存在
        validateHouseExists(updateReqVO.getId());

        // 校验项目存在
        projectService.validateProjectExists(updateReqVO.getProjectId());

        // 更新
        CoreHouseDO updateObj = CoreHouseConvert.INSTANCE.convert(updateReqVO);

        // 自动生成完整房号
        if (updateObj.getFullRoomNumber() == null || updateObj.getFullRoomNumber().isEmpty()) {
            updateObj.setFullRoomNumber(generateFullRoomNumber(updateObj.getBuilding(), updateObj.getFloor(), updateObj.getRoomNumber()));
        }

        houseMapper.updateById(updateObj);
    }

    @Override
    public void deleteHouse(Long id) {
        // 校验存在
        validateHouseExists(id);
        // 删除
        houseMapper.deleteById(id);
    }



    @Override
    public CoreHouseRespVO getHouse(Long id) {
        CoreHouseDO house = houseMapper.selectById(id);
        if (house == null) {
            return null;
        }

        CoreHouseRespVO respVO = CoreHouseConvert.INSTANCE.convert(house);

        // 填充关联信息
        fillHouseInfo(respVO);
        return respVO;
    }

    @Override
    public PageResult<CoreHouseRespVO> getHousePage(CoreHousePageReqVO pageReqVO) {
        PageResult<CoreHouseDO> pageResult = houseMapper.selectPage(pageReqVO);
        PageResult<CoreHouseRespVO> respPageResult = CoreHouseConvert.INSTANCE.convertPage(pageResult);

        // 填充关联信息
        fillHouseInfoBatch(respPageResult.getList());
        return respPageResult;
    }

    @Override
    public PageResult<CoreHouseImportExcelVO> getHouseList(CoreHousePageReqVO pageReqVO) {
        PageResult<CoreHouseDO> pageResult = houseMapper.selectPage(pageReqVO);
        return BeanUtils.toBean(pageResult, CoreHouseImportExcelVO.class);
    }

    @Override
    public void validateHouseExists(Long id) {
        if (id == null) {
            return;
        }
        CoreHouseDO house = houseMapper.selectById(id);
        if (house == null) {
            throw exception(HOUSE_NOT_EXISTS);
        }
    }


    @Override
    public CoreHouseDO getHouseRaw(Long id) {
        return houseMapper.selectById(id);
    }

    @Override
    public List<CoreHouseRespVO> getHouseListByProjectId(Long projectId) {
        List<CoreHouseDO> houses = houseMapper.selectListByProjectId(projectId);
        List<CoreHouseRespVO> respVOs = CoreHouseConvert.INSTANCE.convertList(houses);

        // 填充关联信息
        fillHouseInfoBatch(respVOs);
        return respVOs;
    }

    @Override
    public List<CoreHouseDO> getHouseListByProjectIdRaw(Long projectId) {
        return houseMapper.selectListByProjectId(projectId);
    }

    @Override
    public long countByProjectIdAndStatus(Long projectId, Integer status) {
        return houseMapper.selectCountByProjectIdAndStatus(projectId, status);
    }

    @Override
    public CoreHouseRespVO getHouseByWaterMeterNumber(String waterMeterNumber) {
        List<CoreHouseDO> houses = houseMapper.selectListByWaterMeterNumber(waterMeterNumber);
        if (CollUtil.isEmpty(houses)) {
            return null;
        }

        CoreHouseRespVO respVO = CoreHouseConvert.INSTANCE.convert(houses.get(0));
        fillHouseInfo(respVO);
        return respVO;
    }

    @Override
    public CoreHouseRespVO getHouseByElectricityMeterNumber(String electricityMeterNumber) {
        List<CoreHouseDO> houses = houseMapper.selectListByElectricityMeterNumber(electricityMeterNumber);
        if (CollUtil.isEmpty(houses)) {
            return null;
        }

        CoreHouseRespVO respVO = CoreHouseConvert.INSTANCE.convert(houses.get(0));
        fillHouseInfo(respVO);
        return respVO;
    }

    @Override
    public CoreHouseRespVO getHouseByLockNumber(String lockNumber) {
        List<CoreHouseDO> houses = houseMapper.selectListByLockNumber(lockNumber);
        if (CollUtil.isEmpty(houses)) {
            return null;
        }

        CoreHouseRespVO respVO = CoreHouseConvert.INSTANCE.convert(houses.get(0));
        fillHouseInfo(respVO);
        return respVO;
    }

    @Override
    public List<CoreHouseRespVO> getHouseListByBuildingAndFloor(String building, String floor) {
        List<CoreHouseDO> houses = houseMapper.selectListByBuildingAndFloor(building, floor);
        List<CoreHouseRespVO> respVOs = CoreHouseConvert.INSTANCE.convertList(houses);

        // 填充关联信息
        fillHouseInfoBatch(respVOs);
        return respVOs;
    }

    @Override
    public BigDecimal calculateTotalRentByProjectId(Long projectId) {
        List<CoreHouseDO> houses = houseMapper.selectListByProjectId(projectId);

        BigDecimal totalRent = BigDecimal.ZERO;
        for (CoreHouseDO house : houses) {
            if (house.getRent() != null && house.getStatus() != null && house.getStatus() == 1) { // 只统计已出租的房源租金
                totalRent = totalRent.add(house.getRent());
            }
        }

        return totalRent;
    }

    @Override
    public void batchUpdateHouseStatus(List<Long> ids, Integer status) {
        if (CollUtil.isEmpty(ids)) {
            return;
        }

        houseMapper.batchUpdateStatus(ids, status);
    }

    /**
     * 设置房源的关联信息
     *
     * @param house 房源
     */
    private void fillHouseInfo(CoreHouseRespVO house) {
        if (house == null) {
            return;
        }

        // 填充项目信息
        if (house.getProjectId() != null) {
            CoreProjectDO project = projectService.getProjectRaw(house.getProjectId());
            if (project != null) {
                house.setProjectName(project.getName());
                house.setOwnerUserName(getUserName(project.getOwnerUserId()));
                house.setOwnerDeptName(getDeptName(getUserDeptId(project.getOwnerUserId())));
            }
        }

        // 填充字典名称
        fillDictNames(house);
    }

    /**
     * 批量设置房源的关联信息
     *
     * @param houses 房源列表
     */
    private void fillHouseInfoBatch(List<CoreHouseRespVO> houses) {
        if (CollUtil.isEmpty(houses)) {
            return;
        }

        // 收集项目ID
        List<Long> projectIds = houses.stream()
                .map(CoreHouseRespVO::getProjectId)
                .filter(Objects::nonNull)
                .distinct()
                .collect(Collectors.toList());
        if (CollUtil.isEmpty(projectIds)) {
            return;
        }

        // 获取项目信息
        List<CoreProjectDO> projects = projectIds.stream()
                .map(projectService::getProjectRaw)
                .filter(project -> project != null)
                .toList();

        // 检查是否所有项目都存在
        Set<Long> foundProjectIds = projects.stream()
                .map(CoreProjectDO::getId)
                .collect(Collectors.toSet());

        Set<Long> missingProjectIds = projectIds.stream()
                .filter(projectId -> !foundProjectIds.contains(projectId))
                .collect(Collectors.toSet());

        if (!missingProjectIds.isEmpty()) {
            log.warn("以下项目ID不存在：{}", missingProjectIds);
        }

        // 构建项目信息映射
        Map<Long, CoreProjectDO> projectMap = projects.stream()
                .collect(Collectors.toMap(
                        CoreProjectDO::getId,
                        project -> project,
                        (existing, replacement) -> existing // 如果有重复键，保留现有的
                ));

        // 批量填充信息
        houses.forEach(house -> {
            CoreProjectDO project = projectMap.get(house.getProjectId());
            if (project != null) {
                house.setProjectName(project.getName());
                house.setOwnerUserName(getUserName(project.getOwnerUserId()));
                house.setOwnerDeptName(getDeptName(getUserDeptId(project.getOwnerUserId())));
            }

            // 填充字典名称
            fillDictNames(house);
        });
    }

    /**
     * 填充字典名称
     *
     * @param house 房源
     */
    private void fillDictNames(CoreHouseRespVO house) {
        // 填充房源类型名称
        if (house.getHouseType() != null) {
            house.setHouseTypeName(getHouseTypeName(house.getHouseType()));
        }

        // 填充房源状态名称
        if (house.getStatus() != null) {
            house.setStatusName(getHouseStatusName(house.getStatus()));
        }
    }

    /**
     * 生成完整房号
     */
    private String generateFullRoomNumber(String building, String floor, String roomNumber) {
        StringBuilder fullRoomNumber = new StringBuilder();

        if (building != null && !building.isEmpty()) {
            fullRoomNumber.append(building);
        }

        if (floor != null && !floor.isEmpty()) {
            if (fullRoomNumber.length() > 0) {
                fullRoomNumber.append("-");
            }
            fullRoomNumber.append(floor);
        }

        if (roomNumber != null && !roomNumber.isEmpty()) {
            if (fullRoomNumber.length() > 0) {
                fullRoomNumber.append("-");
            }
            fullRoomNumber.append(roomNumber);
        }

        return fullRoomNumber.toString();
    }

    /**
     * 根据用户ID获取用户名
     */
    private String getUserName(Long userId) {
        if (userId == null) {
            return null;
        }
        AdminUserRespDTO user = adminUserApi.getUser(userId);
        return user != null ? user.getNickname() : null;
    }

    /**
     * 根据用户ID获取部门ID
     */
    private Long getUserDeptId(Long userId) {
        if (userId == null) {
            return null;
        }
        AdminUserRespDTO user = adminUserApi.getUser(userId);
        return user != null ? user.getDeptId() : null;
    }

    /**
     * 根据部门ID获取部门名
     */
    private String getDeptName(Long deptId) {
        if (deptId == null) {
            return null;
        }
        DeptRespDTO dept = deptApi.getDept(deptId);
        return dept != null ? dept.getName() : null;
    }

    /**
     * 获取房源类型名称
     */
    private String getHouseTypeName(Integer houseType) {
        if (houseType == null) {
            return null;
        }
        switch (houseType) {
            case 1: return "住宅";
            case 2: return "商铺";
            case 3: return "写字楼";
            case 4: return "仓库";
            default: return "未知";
        }
    }

    /**
     * 获取房源状态名称
     */
    private String getHouseStatusName(Integer status) {
        if (status == null) {
            return null;
        }
        switch (status) {
            case 0: return "空置";
            case 1: return "已出租";
            case 2: return "装修中";
            case 3: return "维修中";
            default: return "未知";
        }
    }

    @Override
    public CoreHouseImportRespVO importHouseList(List<CoreHouseImportExcelVO> importData) {
        // 校验导入数据不为空
        if (CollUtil.isEmpty(importData)) {
            throw exception(HOUSE_IMPORT_LIST_IS_EMPTY);
        }

        CoreHouseImportRespVO respVO = new CoreHouseImportRespVO();
        respVO.setCreateCount(0);
        respVO.setUpdateCount(0);
        List<CoreHouseImportFailVO> failList = new ArrayList<>();

        // 获取所有项目ID，批量校验项目是否存在
        Set<Long> projectIds = importData.stream()
                .map(CoreHouseImportExcelVO::getProjectId)
                .collect(Collectors.toSet());
        Map<Long, CoreProjectDO> projectMap = projectIds.stream()
                .map(projectService::getProjectRaw)
                .filter(project -> project != null)
                .collect(Collectors.toMap(
                        CoreProjectDO::getId,
                        project -> project,
                        (existing, replacement) -> existing // 如果有重复键，保留现有的
                ));

        // 遍历处理每条导入数据
        for (int i = 0; i < importData.size(); i++) {
            CoreHouseImportExcelVO importVO = importData.get(i);
            int rowIndex = i + 1; // Excel行号从1开始

            try {
                // 校验数据格式
                validateImportData(importVO);

                // 校验项目是否存在
                CoreProjectDO project = projectMap.get(importVO.getProjectId());
                if (project == null) {
                    failList.add(new CoreHouseImportFailVO(rowIndex,
                            generateHouseInfo(importVO),
                            "项目不存在，项目ID【" + importVO.getProjectId() + "】"));
                    continue;
                }

                // 校验项目状态
                if (project.getStatus() != null && project.getStatus() == 1) {
                    failList.add(new CoreHouseImportFailVO(rowIndex,
                            generateHouseInfo(importVO),
                            "项目已停用，无法添加房源"));
                    continue;
                }

                // 检查是否存在相同房源（小区-楼栋-楼层-房间号）
                String fullRoomNumber = generateFullRoomNumber(importVO.getBuilding(),
                        importVO.getFloor(), importVO.getRoomNumber());
                List<CoreHouseDO> existingHouses = houseMapper.selectList(
                        new LambdaQueryWrapperX<CoreHouseDO>()
                                .eq(CoreHouseDO::getProjectId, importVO.getProjectId())
                                .eq(CoreHouseDO::getCommunityName, importVO.getCommunityName())
                                .eq(CoreHouseDO::getBuilding, importVO.getBuilding())
                                .eq(CoreHouseDO::getFloor, importVO.getFloor())
                                .eq(CoreHouseDO::getRoomNumber, importVO.getRoomNumber()));

                // 检查设备编号是否重复（水表、电表、门锁）
                if (importVO.getWaterMeterNumber() != null && !importVO.getWaterMeterNumber().trim().isEmpty()) {
                    List<CoreHouseDO> sameWaterMeterHouses = houseMapper.selectListByWaterMeterNumber(importVO.getWaterMeterNumber());
                    if (CollUtil.isNotEmpty(sameWaterMeterHouses)) {
                        boolean hasConflict = sameWaterMeterHouses.stream()
                                .anyMatch(house -> !house.getProjectId().equals(importVO.getProjectId()) ||
                                        !existingHouses.contains(house));
                        if (hasConflict) {
                            failList.add(new CoreHouseImportFailVO(rowIndex,
                                    generateHouseInfo(importVO),
                                    "水表编号已存在：" + importVO.getWaterMeterNumber()));
                            continue;
                        }
                    }
                }

                if (importVO.getElectricityMeterNumber() != null && !importVO.getElectricityMeterNumber().trim().isEmpty()) {
                    List<CoreHouseDO> sameElectricityMeterHouses = houseMapper.selectListByElectricityMeterNumber(importVO.getElectricityMeterNumber());
                    if (CollUtil.isNotEmpty(sameElectricityMeterHouses)) {
                        boolean hasConflict = sameElectricityMeterHouses.stream()
                                .anyMatch(house -> !house.getProjectId().equals(importVO.getProjectId()) ||
                                        !existingHouses.contains(house));
                        if (hasConflict) {
                            failList.add(new CoreHouseImportFailVO(rowIndex,
                                    generateHouseInfo(importVO),
                                    "电表编号已存在：" + importVO.getElectricityMeterNumber()));
                            continue;
                        }
                    }
                }

                if (importVO.getLockNumber() != null && !importVO.getLockNumber().trim().isEmpty()) {
                    List<CoreHouseDO> sameLockHouses = houseMapper.selectListByLockNumber(importVO.getLockNumber());
                    if (CollUtil.isNotEmpty(sameLockHouses)) {
                        boolean hasConflict = sameLockHouses.stream()
                                .anyMatch(house -> !house.getProjectId().equals(importVO.getProjectId()) ||
                                        !existingHouses.contains(house));
                        if (hasConflict) {
                            failList.add(new CoreHouseImportFailVO(rowIndex,
                                    generateHouseInfo(importVO),
                                    "门锁编号已存在：" + importVO.getLockNumber()));
                            continue;
                        }
                    }
                }

                // 转换为DO对象
                CoreHouseDO houseDO = convertImportToDO(importVO, fullRoomNumber);

                if (CollUtil.isEmpty(existingHouses)) {
                    // 新增房源
                    try {
                        houseMapper.insert(houseDO);
                        respVO.setCreateCount(respVO.getCreateCount() + 1);
                        log.debug("成功创建房源：{}", generateHouseInfo(importVO));
                    } catch (Exception e) {
                        log.error("创建房源失败：{}", generateHouseInfo(importVO), e);
                        failList.add(new CoreHouseImportFailVO(rowIndex,
                                generateHouseInfo(importVO),
                                "创建房源失败：" + e.getMessage()));
                        continue;
                    }
                } else {
                    // 更新房源
                    CoreHouseDO existingHouse = existingHouses.get(0);
                    houseDO.setId(existingHouse.getId());
                    try {
                        houseMapper.updateById(houseDO);
                        respVO.setUpdateCount(respVO.getUpdateCount() + 1);
                        log.debug("成功更新房源：{}", generateHouseInfo(importVO));
                    } catch (Exception e) {
                        log.error("更新房源失败：{}", generateHouseInfo(importVO), e);
                        failList.add(new CoreHouseImportFailVO(rowIndex,
                                generateHouseInfo(importVO),
                                "更新房源失败：" + e.getMessage()));
                        continue;
                    }
                }

            } catch (IllegalArgumentException e) {
                // 数据校验异常
                log.warn("房源导入第{}行数据校验失败：{}", rowIndex, e.getMessage());
                failList.add(new CoreHouseImportFailVO(rowIndex,
                        generateHouseInfo(importVO),
                        "数据格式错误：" + e.getMessage()));
            } catch (Exception e) {
                // 其他异常
                log.error("房源导入第{}行处理失败", rowIndex, e);
                failList.add(new CoreHouseImportFailVO(rowIndex,
                        generateHouseInfo(importVO),
                        "系统错误：" + e.getMessage()));
            }
        }

        respVO.setFailList(failList);
        log.info("房源导入完成：成功创建{}个，更新{}个，失败{}个",
                respVO.getCreateCount(), respVO.getUpdateCount(), failList.size());

        return respVO;
    }

    /**
     * 校验导入数据
     */
    private void validateImportData(CoreHouseImportExcelVO importVO) {
        // 使用Validator进行数据校验
        Set<ConstraintViolation<CoreHouseImportExcelVO>> violations = validator.validate(importVO);
        if (!violations.isEmpty()) {
            String errorMessage = violations.iterator().next().getMessage();
            throw new IllegalArgumentException(errorMessage);
        }

        // 业务逻辑校验
        if (importVO.getProjectId() != null && importVO.getProjectId() <= 0) {
            throw new IllegalArgumentException("项目ID必须为正整数");
        }

        if (importVO.getArea() != null && importVO.getArea().compareTo(BigDecimal.ZERO) <= 0) {
            throw new IllegalArgumentException("房源面积必须大于0");
        }

        if (importVO.getRent() != null && importVO.getRent().compareTo(BigDecimal.ZERO) <= 0) {
            throw new IllegalArgumentException("租金必须大于0");
        }

        if (importVO.getHouseType() != null && (importVO.getHouseType() < 1 || importVO.getHouseType() > 4)) {
            throw new IllegalArgumentException("房源类型无效，请填写1-4之间的数字（1-住宅，2-商铺，3-写字楼，4-仓库）");
        }

        if (importVO.getStatus() != null && (importVO.getStatus() < 0 || importVO.getStatus() > 3)) {
            throw new IllegalArgumentException("房源状态无效，请填写0-3之间的数字（0-空置，1-已出租，2-装修中，3-维修中）");
        }

        // 校验经纬度范围
        if (importVO.getLongitude() != null) {
            if (importVO.getLongitude().compareTo(new BigDecimal("-180")) < 0 ||
                importVO.getLongitude().compareTo(new BigDecimal("180")) > 0) {
                throw new IllegalArgumentException("经度必须在-180到180之间");
            }
        }

        if (importVO.getLatitude() != null) {
            if (importVO.getLatitude().compareTo(new BigDecimal("-90")) < 0 ||
                importVO.getLatitude().compareTo(new BigDecimal("90")) > 0) {
                throw new IllegalArgumentException("纬度必须在-90到90之间");
            }
        }

        // 校验手机号格式（如果不为空）
        if (importVO.getContactPhone() != null && !importVO.getContactPhone().trim().isEmpty()) {
            if (!importVO.getContactPhone().matches("^1[3-9]\\d{9}$") &&
                !importVO.getContactPhone().matches("^\\d{3,4}-\\d{7,8}$")) {
                throw new IllegalArgumentException("联系人手机号格式不正确");
            }
        }
    }

    /**
     * 转换导入数据为DO对象
     */
    private CoreHouseDO convertImportToDO(CoreHouseImportExcelVO importVO, String fullRoomNumber) {
        CoreHouseDO houseDO = new CoreHouseDO();
        houseDO.setProjectId(importVO.getProjectId());
        houseDO.setCommunityName(importVO.getCommunityName());
        houseDO.setBuilding(importVO.getBuilding());
        houseDO.setFloor(importVO.getFloor());
        houseDO.setRoomNumber(importVO.getRoomNumber());
        houseDO.setFullRoomNumber(fullRoomNumber);
        houseDO.setLongitude(importVO.getLongitude());
        houseDO.setLatitude(importVO.getLatitude());
        houseDO.setWaterMeterNumber(importVO.getWaterMeterNumber());
        houseDO.setElectricityMeterNumber(importVO.getElectricityMeterNumber());
        houseDO.setLockNumber(importVO.getLockNumber());
        houseDO.setHouseType(importVO.getHouseType());
        houseDO.setArea(importVO.getArea());
        houseDO.setStatus(importVO.getStatus() != null ? importVO.getStatus() : 0); // 默认空置状态
        houseDO.setRent(importVO.getRent());
        houseDO.setDescription(importVO.getDescription());
        houseDO.setContactName(importVO.getContactName());
        houseDO.setContactPhone(importVO.getContactPhone());
        houseDO.setRemark(importVO.getRemark());
        return houseDO;
    }
    /**
     * 生成房源信息字符串
     */
    private String generateHouseInfo(CoreHouseImportExcelVO importVO) {
        String communityName = importVO.getCommunityName() != null ? importVO.getCommunityName() : "未知小区";
        String building = importVO.getBuilding() != null ? importVO.getBuilding() : "未知楼栋";
        String floor = importVO.getFloor() != null ? importVO.getFloor() : "未知楼层";
        String roomNumber = importVO.getRoomNumber() != null ? importVO.getRoomNumber() : "未知房号";

        return String.format("%s-%s-%s-%s", communityName, building, floor, roomNumber);
    }




}